package spring.AOPDemo.BeforeAdviceTest;

import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.annotations.Test;

public class AspectJProxyTest {

    public static void main(String[] args) {
        Waiter waiter = new NavieWaiter();
        AspectJProxyFactory factory = new AspectJProxyFactory();
        factory.setTarget(waiter);
        factory.addAspect(PreGreetingAspect.class);
        Waiter proxy = factory.getProxy();
        proxy.serveTo("shiqi");
        proxy.greetTo("shiqi");
    }

    @Test
    public void testAnno() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("aspect.xml");
        NavieWaiter waiter = (NavieWaiter)applicationContext.getBean("NavieWaiter");
        waiter.serveTo("shiqi");
        waiter.greetTo("shiqi");
    }

}
